package com.example.framwork.result;

import com.example.framwork.code.CodeConst;
import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;


/**
 * @author Sheeper
 * @date 2018/4/28.
 */
public class ProjectResult extends ObjectResult<Object> implements Serializable {

    private static final long serialVersionUID = -8965417233801324398L;

    private long count;
    //多语言动态数据数组
    private List<Object> vals;

    public ProjectResult() {
        super();
    }

    public ProjectResult(int code, String message) {
        super(code, message);
    }

    public ProjectResult(int code, String message, Object data) {
        super(code, message, data);
    }

    public ProjectResult(int code, String message, Object data, long count) {
        super(code, message, data);
        this.count = count;
    }
//    public ProjectResult(int code, String message, List<Object> vals) {
//        super(code, message);
//        this.vals=vals;
//    }

    public long getCount() {
        return count;
    }

    public void setCount(long count) {
        this.count = count;
    }

    public List<Object> getVals() {
        return vals;
    }

    public void setVals(List<Object> vals) {
        this.vals = vals;
    }

    public static ProjectResult deleteSuccess() {
        return new ProjectResult(CodeConst.SUCCESS, "com_delete_success");
    }

    public static ProjectResult deleteFailed() {
        return new ProjectResult(CodeConst.FAILED, "com_delete_failed");
    }

    public static ProjectResult delete(boolean isSuccess) {
        return isSuccess ? deleteSuccess() : deleteFailed();
    }

    public static ProjectResult insertSuccess() {
        return new ProjectResult(CodeConst.SUCCESS, "com_insert_success");
    }

    public static ProjectResult insertFailed() {
        return new ProjectResult(CodeConst.FAILED, "com_insert_failed");
    }

    public static ProjectResult insert(boolean isSuccess) {
        return isSuccess ? insertSuccess() : insertFailed();
    }

    public static ProjectResult modifySuccess() {
        return new ProjectResult(CodeConst.SUCCESS, "com_modify_success");
    }

    public static ProjectResult modifyFailed() {
        return new ProjectResult(CodeConst.FAILED, "com_modify_failed");
    }

    public static ProjectResult modify(boolean isSuccess) {
        return isSuccess ? modifySuccess() : modifyFailed();
    }

    public static ProjectResult pageSearchSuccess(PageInfo<?> pageInfo) {
        return new ProjectResult(CodeConst.SUCCESS, "com_search_success", pageInfo.getList(), pageInfo.getTotal());
    }

    private static ProjectResult operateSuccess() {
        return new ProjectResult(CodeConst.SUCCESS, "operation_success");
    }

    private static ProjectResult operateFailed() {
        return new ProjectResult(CodeConst.FAILED, "operation_failed");
    }

    public static ProjectResult operate(boolean isSuccess) {
        return isSuccess ? operateSuccess() : operateFailed();
    }

    public static ProjectResult searchSuccess(){
        return new ProjectResult(CodeConst.SUCCESS, "com_search_success");
    }

    public static ProjectResult searchFailed(){
        return new ProjectResult(CodeConst.FAILED, "com_search_failed");
    }

    public static ProjectResult searchSuccess(Object object){
        return new ProjectResult(CodeConst.SUCCESS, "com_search_success", object);
    }

    public static ProjectResult paramError(String message) {
        return new ProjectResult(CodeConst.PARAM_ERROR, message);
    }

    public static ProjectResult error(String message) {
        return new ProjectResult(CodeConst.FAILED, message);
    }

    public static <T> ProjectResult listSuccess(List<T> list) {
        return new ProjectResult(CodeConst.SUCCESS, "查询成功!", list, list.size());
    }
}
